#include <bits/stdc++.h>
 
using namespace std;
 
#define endl '\n'
#define ll long long
#define mod 1000000007

bool prime[1000001];
vector<ll> primes;

void seive(){
    for(int i = 2;i*i<=1000000;i++){
        if(!prime[i])for(int j = i*i;j<=1000000;j+=i)prime[j] = true;
    }
    for(ll i = 2;i<=1000000;i++){
        if(!prime[i])primes.push_back(i);
    }
}

void solve(){
    int d;
    cin>>d;
    ll ans;
    for(int i = 0;i<primes.size();i++){
        if(primes[i] > d){
            for(int j = i+1;j<primes.size();j++){
                if(primes[j] - primes[i] >= d){
                    ans = primes[i]*primes[j];
                    break;
                }
            }
            break;
        }
    }
    for(int i = 0;i<primes.size();i++){
        if(primes[i] > d){
            ans = min(ans,primes[i]*primes[i]*primes[i]);
            break;
        }
    }
    cout<<ans<<endl;
}
 
int main() {
    seive();
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t;
    cin>>t;
    while(t--){
        solve();
    } 
    return 0;
}